package com.roger.homecenterscreen.data.repository

import com.roger.homecenterscreen.data.api.ApiService
import com.roger.homecenterscreen.data.model.ContentData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class ContentRepository(private val apiService: ApiService) {
    
    suspend fun getCustomContent(): Result<ContentData> = withContext(Dispatchers.IO) {
        try {
            val response = apiService.getCustomContent()
            if (response.isSuccessful && response.body()?.success == true) {
                response.body()?.data?.let { data ->
                    Result.success(data)
                } ?: Result.failure(Exception("数据为空"))
            } else {
                val error = response.body()?.error
                Result.failure(Exception(error?.message ?: "请求失败"))
            }
        } catch (e: Exception) {
            Result.failure(e)
        }
    }
} 